package com.yuma.delegate.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyTest {
    public static void main(String[] args) {
        // 被代理的对象
        Star star = new Star();

        // 接口引用 指向了代理对象
        /*
          ClassLoader loader,
          Class<?>[] interfaces, 被代理对象类的所有接口
          InvocationHandler h
         */
        Sing s = (Sing) Proxy.newProxyInstance(
                Sing.class.getClassLoader(),
                Star.class.getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("某明星要登场了");
                        method.invoke(star,args);
                        System.out.println("某明星要退场了");
                        return null;
                    }
                }
        );

        s.sing();
    }
}
